package com.qf.listen;

import com.qf.Constant.RabbitMqConstant;
import com.qf.entity.OrderEntity;
import com.qf.service.OrderService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 你的名字
 * @Date: 2021/07/27/21:13
 * @Description:
 */
@Component
@Slf4j
public class RabbitMQListen {
    @Autowired
    private OrderService orderService;
    @RabbitListener(queues = RabbitMqConstant.ORDER_DLX_QUEUE)
    public void upstatus(OrderEntity orderEntity, Channel channel, Message message)  {
        OrderEntity entity = orderService.getById2(orderEntity.getOid());
        Integer status = entity.getStatus();
        switch (status){
            case 1:
                //未支付,更改订单状态
                orderService.updateOrderStatus(orderEntity.getOid(),4);
           break;
            case 2:
                //已支付
               log.debug("已支付状态");
               break;
            case 3:
                orderService.updateOrderStatus(orderEntity.getOid(),3);

                log.debug("已取消状态......");
                break;
        }

    }
}
